package com.szrt.day20170427.designmodel.demo02;

import java.lang.reflect.Method;

import org.junit.Test;

public class BydCarTest {
	
	@Test
	public void common() throws Exception {
		
		
		BydCar car  = new BydCar();
		car.setPrice(68000);
		System.out.println(car);
		
	}
	
	
	@Test
	public void reflectTest() throws Exception {
		
		//照妖镜
		Class clazz = Class.forName("com.szrt.day20170427.designmodel.demo02.BydCar");
		
		//盗用BydCar的构造方法
		BydCar car = (BydCar) clazz.newInstance();
		
		//拿到setPrice方法
		Method method = clazz.getMethod("setPrice", int.class);
		
		method.invoke(car, 69000);
		
		System.out.println(car);
	}
	
	@Test
	public void factoryTest() throws Exception {
		
		//坑德基中点餐  红萝卜炒白萝卜
		Car car = CarFactory.generateCar("byd");
		
		car.setPrice(70000);
		
		System.out.println(car);
		
	}

}
